/*
 ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1

 * The contents of this file are subject to the Mozilla Public License Version 
 * 1.1 (the "License"); you may not use this file except in compliance with 
 * the License. You may obtain a copy of the License at 
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Blazing Games Inc. (Billy D. Spelchan) code.
 *
 * The Initial Developer of the Original Code is
 * Blazing Games Inc.
 * Portions created by the Initial Developer are Copyright (C) 1999, 2003, 2005-2006
 * the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s):
 *
 ***** END LICENSE BLOCK *****
 */
package com.blazinggames.holeman;

public class Sprite {
// *** CONSTANTS ***
  public final static int FRM_PLAYER = 0;
  public final static int FRM_PLAYER_WALKR0 = 1;
  public final static int FRM_PLAYER_WALKR1 = 2;
  public final static int FRM_PLAYER_WALKR2 = 3;
  public final static int FRM_PLAYER_WALKL0 = 4;
  public final static int FRM_PLAYER_WALKL1 = 5;
  public final static int FRM_PLAYER_WALKL2 = 6;
  public final static int FRM_PLAYER_LADDER0 = 7;
  public final static int FRM_PLAYER_LADDER1 = 8;
  public final static int FRM_PLAYER_LADDER2 = 9;
  public final static int FRM_PLAYER_ROPE0 = 10;
  public final static int FRM_PLAYER_ROPE1 = 11;
  public final static int FRM_PLAYER_ROPE2 = 12;
  public final static int FRM_PLAYER_FALL0 = 13;
  public final static int FRM_PLAYER_FALL1 = 14;
  public final static int FRM_PLAYER_FALL2 = 15;

  public final static int FRM_PLAYER_CHAINR0 = 16;
  public final static int FRM_PLAYER_CHAINR1 = 17;
  public final static int FRM_PLAYER_CHAINR2 = 18;
  public final static int FRM_PLAYER_CHAINL0 = 19;
  public final static int FRM_PLAYER_CHAINL1 = 20;
  public final static int FRM_PLAYER_CHAINL2 = 21;
  public final static int FRM_PLAYER_HOLER = 22;
  public final static int FRM_PLAYER_HOLEL = 23;
  public final static int FRM_CRYSTAL = 24;
  public final static int FRM_HOLE = 28;

  public final static int FRM_HOLE_MAKE = 32;
  public final static int FRM_HOLE_DESTROY = 40;

  public final static int FRM_MONSTER = 48;
  public final static int FRM_MONSTER_WALKR0 = 48;
  public final static int FRM_MONSTER_WALKR1 = 49;
  public final static int FRM_MONSTER_WALKR2 = 50;
  public final static int FRM_MONSTER_WALKL0 = 51;
  public final static int FRM_MONSTER_WALKL1 = 52;
  public final static int FRM_MONSTER_WALKL2 = 53;
  public final static int FRM_MONSTER_FALL0 = 54;
  public final static int FRM_MONSTER_FALL1 = 55;
  public final static int FRM_MONSTER_ROPE0 = 56;
  public final static int FRM_MONSTER_ROPE1 = 57;
  public final static int FRM_MONSTER_CHAIN0 = 58;
  public final static int FRM_MONSTER_CHAIN1 = 59;
  public final static int FRM_MONSTER_CHAIN2 = 60;
  public final static int FRM_MONSTER_LADDER0 = 61;
  public final static int FRM_MONSTER_LADDER1 = 62;
  public final static int FRM_MONSTER_LADDER2 = 63;

  public final static int FRM_MONSTER_DEATH = 64;

  public final static int FRM_PORTHOLE = 72;
  public final static int FRM_EXIT = 76;
  public final static int FRM_SOUND = 78;
  public final static int FRM_NOSOUND = 79;

// *** VARIABLES ***
  int nX, nLastX;
  int nY, nLastY;
  int nImageID;
  int nCurDelay, nAnimLoop;
  boolean bVisible, bCrystal ;

// *** CONSTRUCTORS ***
  public Sprite() {
    nX = nLastX = 0;
    nY = nLastY = 0;
    nImageID = FRM_CRYSTAL;
    nAnimLoop = 0;
    bVisible = true;
    bCrystal = true;
  }

  public Sprite(int x, int y, boolean b) {
    nX = nLastX = x;
    nY = nLastY = y;
    nImageID = FRM_CRYSTAL;
    nAnimLoop = 0;
    bVisible = b;
    bCrystal = true;
  }

// *** METHODS - SET ***
  public void setX(int x) {
    nX = x;
  }

  public void setY(int y) {
    nY = y;
  }

  public void setLastX(int x) {
    nLastX = x;
  }

  public void setLastY(int y) {
    nLastY = y;
  }

  public void setLastLocation(int x, int y) {
    nLastX = x;
    nLastY = y;
  }

  public void setLastLocation() {
    nLastX = nX;
    nLastY = nY;
  }

  public void setVisible(boolean b) {
    bVisible = b;
  }

// *** METHDOS - GET ***
  public int getX() {
    return nX;
  }

  public int getY() {
    return nY;
  }

  public int getLastX() {
    return nLastX;
  }

  public int getLastY() {
    return nLastY;
  }

  public int getMapX() {
    return nX / 32;
  }

  public int getMapY() {
    return nY / 32;
  }

  public boolean isVisible() {
    return bVisible;
  }

  public int getImageID() {
    return nImageID;
  }

  public String toString() {
    if (bVisible)
      return "Visible Sprite " + nX + "," + nY;
    else
      return "Hidden Sprite " + nX + "," + nY;
  }

// *** METHODS - Actions ***

  /**
    Performs marks actions (if any) for turn.  Returns true if still active or
    false if should be removed from it's list.
  */
  public boolean doUpdate(Map map) {
    if (checkDelay(map.getDelay())) {
      ++nAnimLoop;
      if (nAnimLoop >= 8)
        nAnimLoop = 0;
      if (nAnimLoop > 3)
        nImageID = FRM_CRYSTAL + 7 - nAnimLoop;
      else
        nImageID = FRM_CRYSTAL + nAnimLoop;
    }
    return true;
  }

  public boolean checkDelay(int nDelay) {
    ++nCurDelay;
    if (nCurDelay > nDelay) {
      nCurDelay = 0;
      return true;
    }
    else
      return false;
  }

  public boolean isCrystal() {
    return bCrystal;
  }

}
